/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.common.utils.ValidList;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.modules.admin.dto.MaintainTimeSubmitDTO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.admin.vo.BuildingMaintainTimeVO;
import org.springblade.modules.admin.service.IBuildingMaintainTimeService;
import org.springblade.core.boot.ctrl.BladeController;

import java.util.List;

/**
 * 项目保养作业时间段表 控制器
 *
 * @author ysq
 * @since 2023-08-29
 */
@RestController
@AllArgsConstructor
@RequestMapping("admin/building/maintain/time")
@Api(value = "项目保养作业时间段表", tags = "项目保养作业时间段表接口")
public class BuildingMaintainTimeController extends BladeController {

	private final IBuildingMaintainTimeService buildingMaintainTimeService;

	/**
	 * 自定义分页 项目保养作业时间段表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "分页", notes = "传入buildingMaintainTime")
	public R<IPage<BuildingMaintainTimeVO>> page(BuildingMaintainTimeVO buildingMaintainTime, Query query) {
		IPage<BuildingMaintainTimeVO> pages = buildingMaintainTimeService.selectBuildingMaintainTimePage(Condition.getPage(query), buildingMaintainTime);
		return R.data(pages);
	}

	/**
	 * 新增或修改 项目保养作业时间段表
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "新增或修改")
	public R submit(@RequestParam Long buildingId, @Valid @RequestBody ValidList<MaintainTimeSubmitDTO> buildingMaintainTimes) {
		return R.status(buildingMaintainTimeService.submit(buildingId, buildingMaintainTimes));
	}

	@GetMapping("/selectMaintainTimes")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "查询项目保养作业时间")
	public R<List<MaintainTimeSubmitDTO>> selectMaintainTimes(@RequestParam Long buildingId) {
		return R.data(buildingMaintainTimeService.selectMaintainTimes(buildingId));
	}
}
